package com.cskaoyan._04oop1._06static;

/**
 * @author Macro_Ray
 * @since 2024/3/7 15:36
 */
public class Demo1 {
    static {
        System.out.println("Static block 1 is called.");
    }

    // 静态变量
    private static int staticVariable = initializeStaticVariable();

    static {
        System.out.println("Static block 2 is called.");
    }

    // 实例变量
    private int instanceVariable;

    {
        System.out.println("Instance block 1 is called.");
        instanceVariable = initializeInstanceVariable();
    }

    {
        System.out.println("Instance block 2 is called.");
    }

    public Demo1() {
        System.out.println("Constructor is called.");
    }

    private static int initializeStaticVariable() {
        System.out.println("Initializing static variable.");
        return 42;
    }

    private int initializeInstanceVariable() {
        System.out.println("Initializing instance variable.");
        return 10;
    }

    public static void main(String[] args) {
        System.out.println("Main method is called.");
        Demo1 instance = new Demo1();
    }
}
